<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>密码找回</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
</head>
<body>
<!-- 导航栏 -->
<div class="nav">
    五子棋对战
    <span class="spacer"></span>
    <a href="login.html">登录</a>
</div>
<!-- 版心 -->
<div class="login-container">
    <!-- 中间的登陆框 -->
    <div class="login-dialog" id="secret">
        <h3>密保问题</h3>
        <div class="row">
            <span>密保问题</span>
            <input type="text" id="question" value="" readonly="readonly">
        </div>
        <div class="row">
            <span>密保答案</span>
            <input type="password" id="answer" placeholder="请输入12字以内的密保答案">
        </div>
        <div class="row">
            <button id="submit" onclick="mysub()">提交</button>
        </div>
    </div>
</div>

    <script>
            // 初始化密保问题
            function initQuestion() {
            var uid = getUrlValue("uid");
            if (uid == "") {
                alert("非法用户!")
                location.href="excessive.html";
                return;
            }
            jQuery.ajax({ 
<!--                url: "http://"+ location.host + "/user/initques",-->

                url: "/user/initques",
                type: "POST",
                data: {"uid": uid},
                success: function(result) {
                    if (result != null && result.code === 200 && result.data != null) {
                        $("#question").attr("value", result.data);
                    } else {
                        alert("访问失败!")
                        location.href = "login.html";
                    }
                }
            });
        }
        initQuestion();

        function mysub(){
            var answer = jQuery("#answer");
            var uid = getUrlValue("uid");
            if (uid == "") {
                alert("非法用户!")
                location.href="excessive.html";
                return;
            }
            if(answer == null){

                answer.focus();
            }
            if(confirm("请确认答案!")){
                jQuery.ajax({
                    url:"http://"+ location.host + "/user/juganswer",
                    type:"POST",
                    data:{"answer":answer.val(),"uid":uid},
                    success:function(result){
                        if (result != null && result.code === 200 && result.data != null) {
                            location.href="secret_update.html?uid="+uid;
                        }else{
                            alert(result.msg);
                        }
                    }
                });
            }
        }
            
    </script>
</body>

</html>
